package com.kws.payment.business;

import com.alipay.api.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * <b>AlipayBusiness</b>
 *
 * @description: AlipayBusiness <br>
 * @date: 2024/10/31 10:02 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */


@Component
@ConfigurationProperties(prefix = "alipay")
public class AlipayBusiness {
    private String APPID;

    private String SELLER_ID;

    private String GATEWAY_URL;

    private String MERCHANT_PRIVATE_KEY;

    private String PUBLIC_KEY;

    private String CONTENT_KEY;

    private String RETURN_URL;

    @Resource
    private Environment config;

    public AlipayClient alipayClient() throws AlipayApiException {
        AlipayConfig alipayConfig = new AlipayConfig();
        //设置网关地址
        alipayConfig.setServerUrl(GATEWAY_URL);
        //设置应用ID
        alipayConfig.setAppId(APPID);
        //设置应用私钥
        alipayConfig.setPrivateKey(config.getProperty("alipay.merchant-private-key"));
        //设置请求格式，固定值json
        alipayConfig.setFormat(AlipayConstants.FORMAT_JSON);
        //设置字符集
        alipayConfig.setCharset(AlipayConstants.CHARSET_UTF8);
        //设置支付宝公钥
        alipayConfig.setAlipayPublicKey(PUBLIC_KEY);
        //设置签名类型
        alipayConfig.setSignType(AlipayConstants.SIGN_TYPE_RSA2);
        //构造client
        AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);

        return alipayClient;
    }

    public String getAPPID() {
        return APPID;
    }

    public void setAPPID(String APPID) {
        this.APPID = APPID;
    }

    public String getSELLER_ID() {
        return SELLER_ID;
    }

    public void setSELLER_ID(String SELLER_ID) {
        this.SELLER_ID = SELLER_ID;
    }

    public String getGATEWAY_URL() {
        return GATEWAY_URL;
    }

    public void setGATEWAY_URL(String GATEWAY_URL) {
        this.GATEWAY_URL = GATEWAY_URL;
    }

    public String getMERCHANT_PRIVATE_KEY() {
        return MERCHANT_PRIVATE_KEY;
    }

    public void setMERCHANT_PRIVATE_KEY(String MERCHANT_PRIVATE_KEY) {
        this.MERCHANT_PRIVATE_KEY = MERCHANT_PRIVATE_KEY;
    }

    public String getPUBLIC_KEY() {
        return PUBLIC_KEY;
    }

    public void setPUBLIC_KEY(String PUBLIC_KEY) {
        this.PUBLIC_KEY = PUBLIC_KEY;
    }

    public String getCONTENT_KEY() {
        return CONTENT_KEY;
    }

    public void setCONTENT_KEY(String CONTENT_KEY) {
        this.CONTENT_KEY = CONTENT_KEY;
    }

    public String getRETURN_URL() {
        return RETURN_URL;
    }

    public void setRETURN_URL(String RETURN_URL) {
        this.RETURN_URL = RETURN_URL;
    }

    public Environment getConfig() {
        return config;
    }

    public void setConfig(Environment config) {
        this.config = config;
    }
}
